#include <openssl/md5.h>
#include <string.h>
#include <stdio.h>

int main()
{
    MD5_CTX ctx;
    unsigned char outmd[16];
    char buffer[1024];
    char filename[32];
    int len=0;
    int i;
    FILE * fp=NULL;
    memset(outmd,0,sizeof(outmd));
    memset(filename,0,sizeof(filename));
    memset(buffer,0,sizeof(buffer));
    printf("请输入文件名，用于计算MD5值:");
    scanf("%s",filename);
    fp=fopen(filename,"rb");
    if(fp==NULL)
    {
        printf("Can't open file\n");
        return 0;
    }

    MD5_Init(&ctx);
    while((len=fread(buffer,1,1024,fp))>0)
    {
        MD5_Update(&ctx,buffer,len);
        memset(buffer,0,sizeof(buffer));
    }
    MD5_Final(outmd,&ctx);

    for(i=0;i<16;i<i++)
    {
        printf("%02X",outmd[i]);
    }
    printf("\n");
    return 0;
}
